﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>首页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <link rel="shortcut icon" href="/favicon.ico" type="/image/x-icon">
    <link rel="apple-touch-icon-precomposed" href="">
    <link rel="stylesheet" href="../source/src/css/main.css?v=08071315"/>
    <script src="../source/src/js/common.js?v=0807"></script>

</head>
<body>


    <script src="../source/plugin/zepto.min.js"></script>
    <script src="../source/src/js/common.js"></script>
    <script>
        var checkOpenId = function (openId) {
            var json = {
                "openId":openId,						/*openID*/
                "account":user.account,
                "key":user.key			           /*关键字*/
            }
            $.ajax({
                url:apiUrl+'/ChkOpenID',
                type:'GET',
                // data:JSON.stringify(json),
                data:{"json":JSON.stringify(json)},
//              dataType :'jsonp',
                success:function(datas){
                    console.log('ChkOpenID datas', datas)
                    if(datas.Success === true && datas.MobiePhone){
                        setCookie('username',encodeURIComponent(datas.MobiePhone),720);
                        location.href = './list.html?v=080071315'
                    }else if(datas.Success ===  false && datas.Msg === '未注册'){
                        location.href = './reg.html?v=080071315'
                    }else {
                        show_error_tip({
                            str: '网络错误'
                        });
                    }

                },
                error:function(datas){
                }
            });
        }

        $(function(){
            var code = getQueryString('code')
            if(code){
                var json = {
                    // "code":"011T9BHi2MGs2I061QDi2t3JHi2T9BHz",						   /*code*/
                    "code":code,						   /*code*/
                    "account":user.account,
                    "key":user.key
                }
                $.ajax({
                    url:apiUrl+'/GetOpenID',
                    type:'GET',
                    // data:JSON.stringify(json),
                    data:{"json":JSON.stringify(json)},
//              dataType :'jsonp',
                    success:function(datas){
                        if(datas.Success === true){ //
                            if(datas.CustCode){
                                console.log('getopenid datas', datas)
                                sessionStorage.setItem('openid', datas.CustCode)
                                sessionStorage.setItem('nickname', datas.EmpCode)
                                sessionStorage.setItem('headimgurl', datas.CustName)
                                checkOpenId(datas.CustCode)
                            }else{
                                show_error_tip({
                                    str:'授权code过期，请返回重试'
                                });
                            }
                        }else{
                            show_error_tip({
                                str:datas.Msg
                            });
                        }
                        console.log(datas)
                    },
                    error:function(datas){
                    }
                });
            }
        })
    </script>
</body>
</html>